var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    catIndex:0,
    catList:[],
    catId:[],
    index: 0,
    is_yu: 0,
    is_online: 0,
    cid: 0,
    info: {},
  },

  //提交信息
  reg: function (e) {
    var that = this;
    var info = e.detail.value;
    var cid = info.cid;
    if (cid==0){
      wx.showToast({
        title: '请选择专科！',
        duration: 2000
      });
      return false;
    }

    wx.request({
      url: app.api.hostUrl + '/Api/User/saveinfo',
      data: {
        uid: app.api.userId,  //会员ID
        hospital: info.hospital,
        position: info.position,
        cztime: info.cztime,
        service: info.service,
        zyjy: info.zyjy,
        cid: cid,
        is_yu: that.data.is_yu,
        is_online: that.data.is_online,
        digest: info.digest,
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {// 设置请求的 header
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        // success
        var status = res.data.status;
        if (status == 1) {
            wx.showToast({
              title: '保存成功！',
              duration: 2000
            });
        } else {
          wx.showToast({
            title: res.data.err,
            duration: 2000
          });
        }
      },
      fail: function () {
        // fail
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    })
  },

  /**
   * 获取是否在线预约
   */
  radioyuChange: function (e) {
    var is_yu = e.detail.value;
    this.setData({
      is_yu: is_yu
    });
  },

  /**
   * 获取是否在线看诊
   */
  radioonChange: function (e) {
    var is_online = e.detail.value;
    this.setData({
      is_online: is_online
    });
  },

  /**
   * 获取专科
   */
  bindChangeCat: function (e) {
    this.setData({
      catIndex: e.detail.value,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.api.hostUrl + '/Api/Doctor/getcatlist',
      method: 'post',
      data: {
        uid: app.api.userId,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var list = res.data.list;
        var cArr = [];
        var cId = [];
        cArr.push('请选择');
        cId.push('0');
        for (var i = 0; i < list.length; i++) {
          cArr.push(list[i].name);
          cId.push(list[i].id);
        }
        that.setData({
          catList: cArr,
          catId: cId,
          info: res.data.info
        });
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

})